<template>
	<view class="box-c d-ai-c ">
		<view class="list-1" >
			<image src="../../static/index/chahua.png" mode="widthFix"></image>
		</view>
		<view class="list-2">
			扫描用户出示的订单二维码完成收款
		</view>
		<view class="list-3" @tap='scan'>
			<image  src="../../static/index/saoma.png" mode="widthFix"></image>
		</view>
		<!-- <button type="default" @tap="sound">声音</button> -->

	</view>
</template>

<script>
	import checkVersion from '@/uni_modules/uni-upgrade-center-app/utils/check-update.js';
	export default {
		data() {
			return {
				title: 'Hello'
			}
		},
		onLoad() {

		},
		methods: {
			sound(){
				this.ScanAudio('http://downsc.chinaz.net/Files/DownLoad/sound1/201906/11582.mp3');//播放语音
			},
			
			getOrderinfo(orderNumber) {
				this.$store.state.md5 = orderNumber
				if(orderNumber.length==64){
					this.$store.state.type=1
					uni.navigateTo({
						url: `/pages/order/payee`
					})
				}else if (orderNumber.length==8){
					this.$store.state.type=2
					this.$api.scanTheMember({
						memberNumber: orderNumber
					}).then((res) => {
						if (res.data.success) {
							this.$store.state.orderInfo = res.data.dataMap
							uni.navigateTo({
								url: `/pages/order/payee`
							})
							return;
						} else {
							if(res.data.code!=20001){
								uni.showToast({
									title: res.data.message,
									duration: 1500,
									icon: "none"
								});
							}
							return;
						}
					})
					
				}else{
					this.$api.orderInfoByOrderNumber({
						orderNumber: orderNumber
					}).then((res) => {
						if (res.data.success) {
							this.$store.state.orderInfo = res.data.dataMap
							uni.navigateTo({
								url: `/pages/order/order`
							})
							return;
						} else {
							if(res.data.code!=20001){
								uni.showToast({
									title: res.data.message,
									duration: 1500,
									icon: "none"
								});
							}
							return;
						}
					})
				}
				
			},
			scan() {
				this.$api.checkShopLogin({}).then((res) =>{
					if(!res.data.success){
						return;
					}else{
						//开始扫码
						this.toHsScanCode({
							evalName: "hs-scancode", //扫码回调监听事件
							msg: "扫一扫", //提示文本
							fil: '0,1,2' //条码类型
						}, res => {
							//扫码成功后 这里自己判断，如果要自己处理结果就返回 true
							
					
							return false
						})
					}
				})
				
			},

			toHsScanCode(options, results) { //这里可以写成一个通用方法
				let _this = this
				const q = Object.entries(options).map(([key, value]) => `${key}=${value}`).join('&')
				uni.$on(options.evalName || "hs-scancode", ([error, res]) => {
					if (res) { //扫码结果
						uni.navigateBack({
							delta: 1,
							animationType: "fade-out", //用 fade-out 关闭页面，减少扫码成功后跳转页面的闪动
							animationDuration: 300,
						})
						if (results && results(res) === true) return;
						_this.getOrderinfo(res.result)
						

					} else {
						if (error.errMsg === "scanCode:fail cancel") toast("扫码取消")
						else toast("扫码出错")
					}
				})
				uni.navigateTo({
					url: `/pages/hs-scancode/hs-scancode?${q}`
				})
			}

		}
	}
</script>

<style lang="less" scoped>
	page {
		background-color: #F8F8F8;

		.list-1 {
			margin-top: 150rpx;

			image {
				width: 420rpx;
				height: 165rpx;
			}
		}

		.list-2 {
			margin-top: 30rpx;
			color: #666666;

		}

		.list-3 {
			margin-top: 70rpx;

			image {
				width: 279rpx;
				height: 279rpx;
			}
		}
	}
</style>
